package com.blindnews.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一响应结果
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    /**
     * 请求状态：1表示成功、0表示失败
     */
    private Integer code;

    /**
     * 请求信息
     */
    private String msg;
    /**
     * 数据
     */
    private Object data;

    private String command;


    /* set()、get()、toString()方法 */

    /**
     * 请求失败的处理方案
     * @param msg 失败信息
     * @return
     */
    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(0);
        result.setMsg(msg);
        return result;
    }

    /**
     * 请求成功的处理方案
     * @param msg 成功信息
     * @param obj 数据
     * @return
     */
    public static Result success(String msg, Object obj ,String command) {
        Result result = new Result();
        result.setCode(1);
        result.setMsg(msg);
        result.setData(obj);
        result.setCommand(command);
        return result;
    }
    public static Result success(String msg, Object obj ) {
        Result result = new Result();
        result.setCode(1);
        result.setMsg(msg);
        result.setData(obj);

        return result;
    }
    public static Result success(){
        Result result = new Result();
        result.setCode(1);

        return result;
    }

    public static Result success(String msg) {
        Result result = new Result();
        result.setCode(1);
        result.setMsg(msg);

        return result;
    }

}



